﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SingleList.aspx.cs" Inherits="OnLineExam.Web.mag.SingleList" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title></title>
	<link href="../../assets/easyui/1.5.4.4/themes/bootstrap/easyui.css" rel="stylesheet" />
	<link href="../../assets/easyui/1.5.4.4/themes/icon.css" rel="stylesheet" />

	<script src="../../assets/easyui/1.5.4.4/jquery.min.js"></script>
	<script src="../../assets/easyui/1.5.4.4/jquery.easyui.min.js"></script>
	<script src="../../assets/easyui/1.5.4.4/locale/easyui-lang-zh_CN.js"></script>
	<link href="../assets/layui/2.2.5/css/layui.css" rel="stylesheet" />

	<script type="text/javascript"><!--
	$(function () {

		$('#tt').datagrid({
			idField: 'ID',
			url: 'Handler/SingleHandler.ashx?type=getlist&depid=<%=Umodel.DepID %>', //?startIndex=0&endIndex=20  /''+ index +'/'
			singleSelect: true,
			columns: [[
				{ field: 'ID', title: '序号' },
				 
				{
					field: 'Title', title: '题目', align: 'center',
					formatter: function (value, rec, index) {
						var e =   filterHtml(value);

						return e.substring(0,20);
					}
				},
				{
					field: 'opt', title: '编辑', align: 'center',
					formatter: function (value, rec, index) {
						var e = '<a href="#" class="easyui-linkbutton" mce_href="#" onclick="edit(' + rec.ID + ')">编辑</a> ';

						return e;
					}
				},
				{
					field: 'opt2', title: '删除', align: 'center',
					formatter: function (value, rec, index) {

						var d = '<a href="#" class="easyui-linkbutton" mce_href="#" onclick="del(' + index + ')">删除</a> ';
						return d;
					}
				}
			]],
			toolbar: [{
				text: '增加', iconCls: 'icon-add', handler: function () {
					$("#type").val("addsave");
					$("#hdID").val("");
					$("#txtTitle").val("");
					$("#txtA").val("");
					$("#txtB").val("");
					$("#txtC").val("");
					$("#txtD").val("");
					$("#selectAnswer").attr("value", "");
					$("#type").val("addsave");
					$("#selectDep").attr("value",'<%=Umodel.DepID %>');
					layuieditInit();
						$('#dd').dialog('open').dialog('setTitle', '添加单选题');
					}
				},
					{ text: '查找', iconCls: 'icon-search' }
				],
				pagination: true, rownumbers: true
			});
		})

		function filterHtml(s) {
			 var dd=s.replace(/<\/?.+?>/g,"");
			var dds = dd.replace(/ /g, "");//dds为得到后的内容
			return dds;
		}

		function view(bh)  //转到查看页面
		{
			window.location.href = 'StuView.aspx?id=' + bh + '&page=stu';

		}
		function edit(bh)  //转到编辑页面
		{
			$.ajax({
				type: "get",
				url: 'Handler/SingleHandler.ashx?c=' + new Date().getMilliseconds() + '&type=edit&ID=' + bh,
				beforeSend: function (XMLHttpRequest) {
					//ShowLoading();
				},
				success: function (data, textStatus) {
					var obj = eval('(' + data.toString() + ')');


					$("#selectPaper").combobox("setValue", obj.PaperID);
					$("#hdID").val(bh);
					$("#txtTitle").val(obj.Title);
					$("#txtA").val(obj.AnswerA);
					$("#txtB").val(obj.AnswerB);
					$("#txtC").val(obj.AnswerC);
					$("#txtD").val(obj.AnswerD);
					$("#selectAnswer").val(obj.Answer);

					$("#type").val("editsave");
					layuieditInit();



					$('#dd').dialog('open').dialog('setTitle', '编辑单选题--' +filterHtml( obj.Title).substring(0,20));

				},
				complete: function (XMLHttpRequest, textStatus) {
					//HideLoading();
				},
				error: function () {
					//请求出错处理
				}
			});

			//window.location.href = 'StuEdit.aspx?id=' + bh;

		}


		function save() {
			layuieditSyncText();
			if ($('#ff').form('validate')) {
				var postdata = {
					selectPaper: $("#selectPaper").combobox("getValue"),
					selectAnswer: $("#selectAnswer").val(),
					hdID: $('#hdID').val(),
					txtTitle: $('#txtTitle').val(),
					txtA: $('#txtA').val(),
					txtC: $('#txtC').val(),
					txtB: $('#txtB').val(),
					txtD: $('#txtD').val(),
					type: $('#type').val()

				};
				$.post('Handler/SingleHandler.ashx?d=' + new Date().getMilliseconds(), postdata, function (rps) {
					$.messager.alert('操作结果', "执行成功，编号为：" + rps, 'info');
					$('#dd').dialog('close');
					$('#tt').datagrid('reload');

				});
			}


		}

		function del(index) {  //删除操作
			$.messager.confirm('确认', '确认删除?', function (row) {
				if (row) {
					var selectedRow = $('#tt').datagrid('getSelected');  //获取选中行
					$.ajax({
						url: 'Handler/SingleHandler.ashx?type=del&id=' + selectedRow.ID,
						//加了个type，作用是以后不管什么删除，都可以转到这个ashx中处理
						success: function () { $.messager.alert('操作结果', "删除成功，编号为：" + selectedRow.ID, 'info'); }
					});
					$('#tt').datagrid('deleteRow', index);
				}
			})
		}
		function onChange(newValue, oldValue) {

			$('#tt').datagrid({
				queryParams: {
					id: newValue
				}
			});
		}
// --></script>
</head>
<body>

	<input id="papers" class="easyui-combobox" name="papers"
		data-options="valueField:'PaperID',textField:'PaperName',url:'Handler/PaperHandler.ashx?type=getlistForSelect',onChange:onChange">
	<table id="tt"></table>

	<div id="dd" class="easyui-dialog" style="height: 650px; width: 750px; padding: 10px 20px" closed="true" buttons="#dd-buttons" resizable="true">


		<form id="ff">
			<input id="hdID" name="hdID" type="hidden" />
			<input id="type" name="type" type="hidden" />
			<input id="hdDepID" name="hdDepID" type="hidden" value='<%=Umodel.DepID %>' />
			<table style="width: 100%">

				<tr>
					<td>试卷：</td>
					<td>
						<input id="selectPaper" class="easyui-combobox" name="selectPaper"
							data-options="valueField:'PaperID',textField:'PaperName',url:'Handler/PaperHandler.ashx?type=getlistForSelect'">
						&nbsp;</td>
				</tr>
				<tr>
					<td>题目:</td>
					<td>
						<textarea id="txtTitle" name="txtTitle" lay-verify="required" style="display:none"></textarea>
					</td>
				</tr>
				<tr>
					<td>A:</td>
					<td>
						<textarea id="txtA" name="txtA" class="easyui-validatebox" required="true"></textarea></td>
				</tr>
				<tr>
					<td>B:</td>
					<td>
						<textarea id="txtB" name="txtB" cols="50" rows="3" class="easyui-validatebox" required="true"></textarea></td>
				</tr>
				<tr>
					<td>C:</td>
					<td>
						<textarea id="txtC" name="txtC" cols="50" rows="3" class="easyui-validatebox" required="true"></textarea></td>
				</tr>
				<tr>
					<td>D:</td>
					<td>
						<textarea id="txtD" name="txtD" cols="50" rows="3" class="easyui-validatebox" required="true"></textarea></td>
				</tr>
				<tr>
					<td>答案:</td>
					<td>

						<select id="selectAnswer" name="selectAnswer" class="easyui-validatebox" required="true" style="width: 200px;">
							<option></option>
							<option value="A">A</option>
							<option value="B">B</option>
							<option value="C">C</option>
							<option value="D">D</option>
						</select></td>
				</tr>
			</table>
		</form>
	</div>
	<div id="dd-buttons">
		<a id="btnSave" href="#" class="easyui-linkbutton" iconcls="icon-ok" onclick="save();">保存</a>
		<%--<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>--%>
		<a href="#" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dd').dialog('close')">取消</a>

	</div>


	<script src="../assets/layui/2.2.5/layui.js"></script>
	<script>
		
		var txtTitle, txtA, txtB, txtC, txtD;
		function layuieditInit() {
			layui.use('layedit', function () {
				var layedit = layui.layedit
					, $ = layui.jquery;
				layedit.set({
					uploadImage: {
						url: '/handler/uploadhandler.ashx' //接口url  
						, type: 'post' //默认post  
					}
				});

				txtTitle = layedit.build('txtTitle', { height: 100 });
				txtA = layedit.build('txtA', { height: 100 });
				txtB = layedit.build('txtB', { height: 100 });
				txtC = layedit.build('txtC', { height: 100 });
				txtD = layedit.build('txtD', { height: 100 });



			});


		}
		function layuieditSyncText() {

			layui.use('layedit', function () {
				var layedit = layui.layedit
					, $ = layui.jquery;

				layedit.sync(txtTitle);
				layedit.sync(txtA);
				layedit.sync(txtB);
				layedit.sync(txtC);
				layedit.sync(txtD);


			});


		}


	</script>


	<script>
		//layui.config({
		//	base: '/mag/layuimodules/single/' //你存放新模块的目录，注意，不是layui的模块目录
		//}).use('index'); //加载入口
	</script>

</body>
</html>
